<template>
    <div>
        <el-table :data="tableData" style="width: 100%" v-loading="loading"
    element-loading-text="操作中，请稍后">
            <el-table-column prop="id" label="企业ID" width="250"></el-table-column>
            <el-table-column prop="companyName" label="公司名称"></el-table-column>
            <el-table-column prop="phone" label="电话"></el-table-column>
            <el-table-column prop="email" label="邮箱"></el-table-column>
            <!-- <el-table-column prop="industry.industryName" label="企业类型"></el-table-column> -->
            <el-table-column label="操作" >
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="updateVisible = false; updatePass(2, scope.row.id)">允许通过</el-button>
                    <el-button type="danger" size="mini" @click="updateVisible = false; updateNotPass(3, scope.row.id)">拒绝通过</el-button>
            </template>
                <!-- <template slot-scope="scope">
                    <el-button type="text" @click="updateVisible = true; listById(scope.row.id);">查看详情</el-button>
                    <el-dialog
                    title="提示"
                    :visible.sync="updateVisible"
                    width="30%"
                    :before-close="handleUpdateClose">
                        <el-form label-width="80px">
                            <el-form-item label="企业ID">
                                <el-input v-model="company.id" placeholder="请输入内容" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="Hr姓名">
                                <el-input v-model="company.hrName" placeholder="请输入内容" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="公司名称">
                                <el-input v-model="company.companyName" placeholder="请输入内容" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="公司介绍">
                                <el-input v-model="company.companyDesc" placeholder="请输入内容" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="电话">
                                <el-input-number v-model="company.phone" :min="1" :max="999999" disabled></el-input-number>
                            </el-form-item>
                            <el-form-item label="邮箱">
                                <el-input-number v-model="company.email" :precision="2" :step="1.00" :max="999999" disabled></el-input-number>
                            </el-form-item>
                            <el-form-item label="是否上市">
                                <el-input v-model="company.beListed" placeholder="请输入内容" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="企业类型">
                                <el-input v-model="company.beListed" placeholder="请输入内容" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="申请资料">
                                <el-input v-model="company.beListed" placeholder="请输入内容" disabled></el-input>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="updateVisible = false">取 消</el-button>
                            <el-button type="primary" @click="updateVisible = false; updatePass(2, scope.row.id)">允许通过</el-button>
                            <el-button type="primary" @click="updateVisible = false; updateNotPass(3, scope.row.id)">拒绝通过</el-button>
                        </span>
                    </el-dialog>
                </template> -->
                
            </el-table-column>
        </el-table>
        <div class="block">
              <el-pagination
                  layout="prev, pager, next"
                  :total="pageHelp.total * 10"
                  @current-change="changeCurrentPage"
                  >
              </el-pagination>
          </div>
    </div>
</template>

<script>
let path = "http://localhost";

import axios from 'axios'
export default {
    data() {
        return {
          tableData: [],
          visible: false,
          updateVisible: false,
          addVisible:false,
          company:{},
          loading:false,
          pageHelp:{
                currentPage : 1,
                perPageSize : 10,
                total:1,
            },
        }
    },
    components:{
        
    },
    methods: {

        warningMessage(info) {
            this.$message({
                message: info,
                type: 'warning'//success、warning
            });
        },
        successMessage(info) {
            this.$message({
                message: info,
                type: 'success'//success、warning
            });
        },
        errorMessage(info) {
            this.$message.error(info);
        },

        //分页查询
        changeCurrentPage(currentPage) {
            console.log(this.pageHelp.currentPage);
            this.pageHelp.currentPage = currentPage;
            axios({
                method: 'get',
                url: "http://localhost/backstage/company/apply",
                params: {
                    currentPage: this.pageHelp.currentPage,
                    perPageSize: this.pageHelp.perPageSize,
                },
                headers: {
                    id: JSON.parse(localStorage.getItem("account")).id,
                    token: JSON.parse(localStorage.getItem("account")).token,
                },

            }).then(res => {
                if (res.data.code === 500) {
                    this.warningMessage("您的权限不足！")
                } else if (res.data.code === 40100) {
                    console.log(res.data.data);
                    this.tableData = res.data.data.list;
                    this.pageHelp.total = res.data.data.pages;
                } else {
                    this.errorMessage("查询失败！");
                }

                console.log(res);
            }).catch(error => {
                console.log(error);
            })
        },

        // 展示所有在申请的企业
        list() {
            axios({
                method: 'GET',
                url: "http://localhost/backstage/company/apply",
                params: {
                    currentPage: this.pageHelp.currentPage,
                    perPageSize: this.pageHelp.perPageSize,
                },
                headers:{
                    id: JSON.parse(localStorage.getItem("account")).id,
                    token: JSON.parse(localStorage.getItem("account")).token,
                }
            }).then(res => {
                this.tableData = res.data.data.list;
                this.pageHelp.total = res.data.data.pages;
            }).catch(error => {
                console.log(error);
            })
        },
        handleUpdateClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
        },
        handleAddClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
        },

        // 展示需要审核的企业的详情
        listById(id){
            axios({
                method:'GET',
                url:"http://localhost/backstage/company/"+id,
                headers:{
                    id: JSON.parse(localStorage.getItem("account")).id,
                    token: JSON.parse(localStorage.getItem("account")).token,
                }
            }).then(res => {
                console.log(res.data.data);
                this.company = res.data.data
            }).catch(error => {
                console.log(error);
            })
        },

        // 企业资质审核通过
        updatePass(status, companyId){
            this.loading=true;
            axios({
                method:'PUT',
                url:'http://localhost/backstage/company/updatePass/'+companyId+"/"+status,
                headers:{
                    id: JSON.parse(localStorage.getItem("account")).id,
                    token: JSON.parse(localStorage.getItem("account")).token,
                }
            }).then(res => {
                this.loading=false;
                if(res.data.code === 500){
                    this.warningMessage("您没有权限！");
                    // alert("你没有权限");
                }else if(res.data.code === 30100){
             
                    this.successMessage("操作成功！");
                    this.list();
                }else{
                  
                    this.errorMessage("操作失败");
                    // alert("更新失败");
                }
                
            }).catch(error => {
                this.loading=false;
                console.log(error);
            })
        },

        // 企业资质审核未通过
        updateNotPass(status, companyId){
            this.loading=true;
            axios({
                method:'PUT',
                url:'http://localhost/backstage/company/updateNotPass/'+companyId+"/"+status,
                headers:{
                    id: JSON.parse(localStorage.getItem("account")).id,
                    token: JSON.parse(localStorage.getItem("account")).token,
                }
            }).then(res => {
                this.loading=false;
                if(res.data.code === 500){
                    this.warningMessage("您没有权限！");
                    
                }else if(res.data.code === 30100){
                    this.successMessage("操作成功！");
                    this.list()
                }else{
                    this.errorMessage("操作失败");
                    // alert("更新失败")
                }
                
            }).catch(error => {
                this.loading=false;
                console.log(error);
            })
        }
    },
    created(){
        this.list();
    }
}
</script>

<style scoped>


</style>